<?php
defined('_JEXEC') or die('Restricted access');
$img_dir = JPATH_SITE.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'fileupload'.DIRECTORY_SEPARATOR;
$img_path = JURI::root(true).'/images/fileupload/';
$title = ($this->id)?"Sửa hợp đồng":"Tạo hợp đồng";

$cache_dir = JPATH_COMPONENT.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR;
$readonly = "";
$disabled = "";
if(!empty($this->id))
{
	$readonly = "readonly";
	$disabled = "disabled";
}
?>
<div class='tab_content' id="tab_create_hopdong">
	<div class='container-fluid container_root margin10'>
		<div class='row-fluid'>
			<div class='widget widget-padding span12'>
				<div class='widget-header'>
					<i class="icon-plus"></i>
					<h5><?php echo $title ?></h5>
				</div>
				<div class='widget-body'>
								
					<form class='form' id="form_create_hopdong" method="post" action="index.php">
						<div class='row-fluid'>
							<div class='span12'>
								<button type="submit" class='btn btn-primary'>
									<i class='icon-ok icon-white'></i>
									<?php echo JText::_("COM_KETNOI_SAVEBTN") ?>
								</button>
								
								<a type="submit" href="#hopdong" class='btn'>
									<i class='icon-reorder icon-white'></i>
									Danh sách
								</a>
							</div>
						</div>
						
						<div class="row-fluid margin10">
							<div class='span12'>
								<div class="row-fluid">
									<div class="span3">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Chọn Serial
												<em>*</em>
											</label>
					                        <div class="controls row-fluid chosen_nocreate">
					                        	<?php if($this->row->id): ?>
					                        		<input readonly value="<?php echo $this->row->serial ?>" type="text" class="span12" />
					                        		<input value="<?php echo $this->row->inventory_id ?>" name="inventory_id" type="hidden" class="span12" />
					                            <?php else: ?>
					                            	<select <?php echo $disabled ?>  data-placeholder="Chọn serial" id="serial" name="inventory_id">
						                            	<?php foreach ($this->serials as $serial): ?>
						                            		<?php $selected = $serial->serial == $this->row->inventory_id?"selected":"" ?>
						                            		<option <?= $selected ?> data-row='<?php echo json_encode($serial) ?>' value="<?php echo $serial->id ?>" >
						                            			<?php echo $serial->serial ?> 
						                            		</option>
						                            	<?php endforeach; ?>
					                            	</select>	
					                        	<?php endif; ?>
					                            
					                        </div>
				                        </div>
									</div>
									
									<div class="span3">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Mã máy
												<em>*</em>
											</label>
					                        <div class="controls row-fluid">
					                            <input readonly type="text" value="<?php echo $this->row->ma_machine ?>" class="span12" id="mamay"/>
					                        </div>
				                        </div>
									</div>
									
									<div class="span3">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Tên máy
												<em>*</em>
											</label>
					                        <div class="controls row-fluid">
					                            <input readonly value="<?php echo $this->row->ten_machine ?>" type="text" class="span12" id="tenmay"/>
					                        </div>
				                        </div>
									</div>
									
									<div class="span3">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Hình thức
												<em>*</em>
											</label>
											<?php if($this->row->id): ?>
												<?php 
													foreach ($this->hinhthucmay as $hinhthuc)
													{
														if($hinhthuc->id == $this->row->hinhthuc)
														{
															$value_hinhthuc = $hinhthuc->ten;
														}
													}
												?>
					                        	<input readonly value="<?php echo $value_hinhthuc ?>" type="text" class="span12" />
					                        	<input value="<?php echo $this->row->hinhthuc ?>" type="hidden" name="hinhthuc" />
					                        <?php else: ?>
					                        <div class="controls row-fluid chosen_nocreate">
					                            <select <?php echo $disabled ?> id="hinhthuc" data-toggle='chosen' name="hinhthuc">
					                            	<?php foreach ($this->hinhthucmay as $hinhthuc): ?>
					                            		<?php $selected = $hinhthuc->id == $this->row->hinhthuc?"selected":"" ?>
					                            		<option <?= $selected ?> value="<?php echo $hinhthuc->id ?>">
					                            			<?php echo $hinhthuc->ten ?>
					                            		</option>
					                            	<?php endforeach; ?>
					                            </select>
					                        </div>
					                        <?php endif; ?>
				                        </div>
									</div>
								</div>
								<div class="row-fluid">
									<div class="span3">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Khách hàng
												<em>*</em>
											</label>
											<?php if($this->row->id): ?>
												<?php 
													foreach ($this->customer as $customer)
													{
														if($customer->id == $this->row->customer_id)
														{
															$value_customer = $customer->ma . " - " .$customer->ten;
														}
													}
												?>
					                        	<input readonly value="<?php echo $value_customer ?>" type="text" class="span12" />
					                        	<input value="<?php echo $this->row->customer_id ?>" type="hidden" name="customer_id" />
					                        <?php else: ?>
					                        <div class="controls row-fluid chosen_multiple chosen_table chosen_quickcreate">
					                            <select multiple data-placeholder="Chọn khách hàng" id="customer" name="customer_id">
					                            	<?php foreach ($this->customer as $customer): ?>
					                            		<?php $selected = $customer->id == $this->row->customer_id?"selected":"" ?>
					                            		<option <?= $selected ?> value="<?php echo $customer->id ?>" data-ten="<?php echo $customer->ten ?>" data-ma="<?php echo $customer->ma ?>">
					                            			<?php echo $customer->ma ?> - <?php echo $customer->ten ?>
					                            		</option>
					                            	<?php endforeach; ?>
					                            </select>
					                            <a class='btn btn-info fix-btn' onclick='showModalCreateCustomer("customer")'>
													<i class='icon icon-plus'></i>
												</a>
					                        </div>
					                        <?php endif; ?>
				                        </div>
									</div>
									
									<div class="span3">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Số tháng bảo hành
											</label>
					                        <div class="controls row-fluid custom">
					                            <input <?php echo $readonly ?> type="text" name="sothangbaohanh" class="span12" value="<?php echo $this->row->sothangbaohanh ?>"/>
					                        </div>
				                        </div>
									</div>
									
									<div class="span3">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Số dung lượng bảo hành
											</label>
					                        <div class="controls row-fluid custom" >
					                        	<input <?php echo $readonly ?> type="text" name="sodungluongbaohanh" class="span12" value="<?php echo $this->row->sodungluongbaohanh ?>"/>
					                        </div>
				                        </div>
									</div>
									
									<div class="span3">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Tình trạng
												<em>*</em>
											</label>
					                        <div class="controls row-fluid chosen_nocreate">
					                            <select id="status" data-toggle='chosen' name="status">
					                            	<?php foreach ($this->hopdong_status as $hopdong_status): ?>
					                            		<?php $selected = $hopdong_status->id == $this->row->status?"selected":"" ?>
					                            		<option <?= $selected ?> value="<?php echo $hopdong_status->id ?>">
					                            			<?php echo $hopdong_status->ten ?>
					                            		</option>
					                            	<?php endforeach; ?>
					                            </select>
					                        </div>
				                        </div>
									</div>
								</div>
								
								<div class="row-fluid hinhthuc_hidden maychothue" style="display:none">
									<div class="span3">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Hợp đồng (tháng)
											</label>
					                        <div class="controls row-fluid custom">
					                            <input <?php echo $readonly ?> type="text" name="hopdong" class="span12" value="<?php echo $this->row->hopdong ?>"/>
					                        </div>
				                        </div>
									</div>
									
									<div class="span3">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Số trang mỗi tháng
											</label>
					                        <div class="controls row-fluid custom">
					                            <input <?php echo $readonly ?> type="text" name="sotrang" class="span12" value="<?php echo $this->row->sotrang ?>"/>
					                        </div>
				                        </div>
									</div>
									
									<div class="span3">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Tiền vượt mức mỗi trang
											</label>
					                        <div class="controls row-fluid custom">
					                            <input <?php echo $readonly ?> type="text" name="tienvuotmuc" class="span12" value="<?php echo $this->row->tienvuotmuc ?>"/>
					                        </div>
				                        </div>
									</div>
									
									<div class="span3">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Thuê bao(tháng)
											</label>
					                        <div class="controls row-fluid custom">
					                            <input <?php echo $readonly ?> type="text" name="thuebao" class="span12" value="<?php echo $this->row->thuebao ?>"/>
					                        </div>
				                        </div>
									</div>
								</div>
								
							</div>
						</div>
						
						<input type="hidden" name="option" value="com_ketnoi" />
						<input type="hidden" name="view" value="hopdong" />
						<input type="hidden" name="task" value="hopdong.save" />
						<input type="hidden" name="layout" value="create" />
						<input type="hidden" name="tmpl" value="raw" />
						<?php if($this->id): ?>
						<input type="hidden" name="id" value="<?= $this->id ?>" />
						<?php endif; ?>
					</form>
				</div>
				
			</div>
		</div>
	</div>
</div>

<script>
	<?php if($this->id): ?>
		setHash("edit_hopdong",<?= json_encode(array("id"=>$this->id)) ?>);
	<?php endif; ?>
</script>
